import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

const router = new Router({
  routes: [{
      path: "/",
      name: "Login",
      component: () => import("@/views/Login")
    },
    {
      path: "/HomePage",
      name: "HomePage",
      redirect: "/Home",
      component: () => import("@/views/HomePage"),
      children: [
        // {
        //   path: "/ChangePsw",
        //   name: "ChangePsw",
        //   component: () => import("@/views/ChangePsw")
        // },
        // {
        //   path: "/UserList",
        //   name: "UserList",
        //   component: () => import("@/views/UserManager/UserList")
        // },
        {
          path: "/UserCheckList",
          name: "UserCheckList",
          component: () => import("@/views/UserManager/UserCheckList")
        },
        {
          path: "/Home",
          name: "Home",
          component: () => import("@/views/Home")
        },
        
        {
          path: "/StaffList",
          name: "StaffList",
          component: () => import("@/views/StaffManager/StaffList")
        },
        {
          path: "/UserInforDetail",
          name: "UserInforDetail",
          component: () => import("@/views/UserManager/UserInforDetail")
        },
        {
          path: "/LineChart",
          name: "LineChart",
          component: () => import("@/views/Chart/LineChart")
        },
        {
          path: "/PineChart",
          name: "PineChart",
          component: () => import("@/views/Chart/PineChart")
        },
        {
          path: "/VisitorList",
          name: "VisitorList",
          component: () => import("@/views/UserManager/VisitorList")
        },
        {
          path: "/HostList",
          name: "HostList",
          component: () => import("@/views/UserManager/HostList")
        }
      ]
    }
  ]
});
router.beforeEach((to, from, next) => {
  let token = localStorage.getItem("ktoken");
  if (to.path === "/") {
    next();
  } else if (!token) {
    next("/");
  } else {
    next();
  }
});
export default router
